package xj.util.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.Icon;

public class ColoredSquare implements Icon {

  protected Color color;

  protected Dimension dim;

  static public final Color defaultColor = Color.red;

  static public final Dimension defaultDim = new Dimension(12, 12);

  public ColoredSquare(Color c) {
    this(c, null);
  }

  public ColoredSquare(Color c, int width, int height) {
    this(c, new Dimension(width, height));
  }

  public ColoredSquare(Color c, Dimension d) {
    this.color = c;
    this.dim = d;
    if (color == null) {
      color = defaultColor;
    }
    if (dim == null) {
      dim = defaultDim;
    }
  }

  public Color getColor() { 
    return color;
  }

  public void setColor(Color color) {
    this.color = color;
  }

  public void paintIcon(Component c, Graphics g, int x, int y) {
    Color oldColor = g.getColor();
    g.setColor(color);
    g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true);
    g.setColor(oldColor);
  }

  public int getIconWidth() {
    return dim.width;
  }

  public int getIconHeight() {
    return dim.height;
  }

}
